<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        let arr = [12, 21, 55, 34, 88, 75, 21, 21, 43, 12, 34, 75]

        // ES6 Set  
        function setFn4(arr) {
            return [...new Set(arr)]
        }
        setFn4(arr)
        console.log(setFn4(arr));

        // 循环+indexOf去重
        function setFn3(arr) {
            let arr2 = []
            for (let i = 0; i < arr.length; i++) {
                if (arr2.indexOf(arr[i]) == -1) {
                    arr2.push(arr[i])
                }
            }
            return arr2
        }
        // setFn3(arr)
        // console.log(setFn3(arr));

        // 利用obj特性去重
        function setFn2(arr) {
            let obj = {}
            for (let v of arr) {
                obj[v] = v
            }
            return Object.keys(obj)
        }

        // setFn2(arr)
        // console.log(setFn2(arr));

        // 双重for循环去重
        function setFn(arr) {
            for (let i = 0; i < arr.length; i++) {
                for (let j = i + 1; j < arr.length; j++) {
                    if (arr[i] == arr[j]) {
                        arr.splice(j, 1)
                        j--
                    }
                }
            }
        }
        // setFn(arr)
        console.log(arr);
    </script>
</body>

</html>